
using System;

public static class Program
{
    private static readonly string[] types = { "int8",
                                               "uint8",
                                               "int16",
                                               "uint16",
                                               "int32",
                                               "uint32",
                                               "int64",
                                               "uint64" };

    private static void w(string a)
    {
        Console.WriteLine(a);
    }

    private static void w()
    {
        Console.WriteLine();
    }

    private static string strcat(params string[] s)
    {
        string r = null;
        for(int i = 0; i < s.Length; i++)
            r += s[i] + "\r\n";
        return r;
    }

    public static void Main()
    {
        w();
        w("\'this file is generated by /osi/root/codegen/unchecked_int2/unchecked_int2.exe");
        w("\'so change /osi/root/codegen/unchecked_int2/unchecked_int2.cs instead of this file");
        w("\'this file works in the project removed integer overflow check");
        w("\'or compile with /removeintchecks+ vbc parameter");
        w();
        w("Imports System.Runtime.CompilerServices");
        w();
        w("Imports int8 = System.SByte");
        w("Imports uint8 = System.Byte");
        w("Imports int16 = System.Int16");
        w("Imports uint16 = System.UInt16");
        w("Imports int32 = System.Int32");
        w("Imports uint32 = System.UInt32");
        w("Imports int64 = System.Int64");
        w("Imports uint64 = System.UInt64");
        w();
        w("Imports int = System.Int32");
        w("Imports uint = System.UInt32");
        w();
        w("Public Module _unchecked");
        for(int i = 0; i < types.Length; i++)
        {
            for(int j = 0; j < types.Length; j++)
            {
                w(strcat(
"    <Extension()> Public Function unchecked_inc(ByVal this As " + types[i] + ", ByVal that As " + types[j] + ") As " + types[i],
"        Return this + that",
"    End Function",
"",
"    <Extension()> Public Function unchecked_dec(ByVal this As " + types[i] + ", ByVal that As " + types[j] + ") As " + types[i],
"        Return this - that",
"    End Function",
"",
"    <Extension()> Public Function unchecked_multiply(ByVal this As " + types[i] + ", ByVal that As " + types[j] + ") As " + types[i],
"        Return this * that",
"    End Function"));
            }
        }
        w("End Module");
        w();

        {
            string c = strcat(
                "Public Structure unchecked_{0}",
                "    Private ReadOnly v As {0}",
                "    Public Sub New(ByVal v As {0})",
                "        Me.v = v",
                "    End Sub", "",
                "    Public Shared Operator +(ByVal this As unchecked_{0}) As {0}",
                "        Return this.v",
                "    End Operator", "",
                "    Public Shared Widening Operator CType(ByVal this As {0}) As unchecked_{0}",
                "        Return New unchecked_{0}(this)",
                "    End Operator", "",
                "    Public Shared Widening Operator CType(ByVal this As unchecked_{0}) As {0}",
                "        Return this.v",
                "    End Operator", "",
                "    Public Shared Operator +(ByVal this As unchecked_{0}, ByVal that As unchecked_{0}) As unchecked_{0}",
                "        Return this + (+that)",
                "    End Operator", "",
                "    Public Shared Operator +(ByVal this As unchecked_{0}, ByVal that As {0}) As unchecked_{0}",
                "        Return New unchecked_{0}((+this) + that)",
                "    End Operator", "",
                "    Public Shared Operator +(ByVal this As {0}, ByVal that As unchecked_{0}) As unchecked_{0}",
                "        Return that + this",
                "    End Operator", "",
                "    Public Shared Operator -(ByVal this As unchecked_{0}, ByVal that As unchecked_{0}) As unchecked_{0}",
                "        Return this - (+that)",
                "    End Operator", "",
                "    Public Shared Operator -(ByVal this As unchecked_{0}, ByVal that As {0}) As unchecked_{0}",
                "        Return New unchecked_{0}((+this) - that)",
                "    End Operator", "",
                "    Public Shared Operator -(ByVal this As {0}, ByVal that As unchecked_{0}) As unchecked_{0}",
                "        Return New unchecked_{0}(this) - that",
                "    End Operator", "",
                "    Public Shared Operator *(ByVal this As unchecked_{0}, ByVal that As unchecked_{0}) As unchecked_{0}",
                "        Return this * (+that)",
                "    End Operator", "",
                "    Public Shared Operator *(ByVal this As unchecked_{0}, ByVal that As {0}) As unchecked_{0}",
                "        Return New unchecked_{0}((+this) * that)",
                "    End Operator", "",
                "    Public Shared Operator *(ByVal this As {0}, ByVal that As unchecked_{0}) As unchecked_{0}",
                "        Return that * this",
                "    End Operator", "",
                "End Structure");
            for(int i = 0; i < types.Length; i++)
                w(string.Format(c, types[i]));
            w(string.Format(c, "int"));
            w(string.Format(c, "uint"));
        }
    }
}

